<script>
    $("#rent_type").live('change', function() {
        var selected_type = $("#rent_type:checked").val();
        if (selected_type == 'Short Term') {
            $("#container_short_term").show("slow");
            $("#container_long_term").hide("slow");
        }
        else {
            $("#container_short_term").hide("slow");
            $("#container_long_term").show("slow");
        }
    });
    
    $("#search_car").live('click', function() {
        $("*[class$='number']:not(span)").each(function(e) {    
            var invalid_number = false;
            var element_val = $(this).val();        
            if(element_val != '') {            
                var reg_number = /^[0-9]*$/;
                if(!reg_number.test(element_val))
                    invalid_number = true;

                var next_element = $(this).parent();
                $(next_element).find('div.error').remove();
            }
            
            if(invalid_number) {
                $(this).css('border-color', 'red');
                $(next_element).append('<div class="error">Invalid number</div>');
                e.preventDefault();
            }
            else 
                $(this).css('border', '1px solid #DADADA');
        });

        $.colorbox({
            iframe: true, 
            width: "44%", 
            height: "37%",
            href: "<?php echo base_url(); ?>index.php/rent/pre_submit/rent_car"
        });
        
        return false;
    });    
</script>
<?php 
    $attributes = array('id' => 'rent_car');
    echo form_open(base_url()."index.php/rent/submit", $attributes); 
?>
    <input type="hidden" id="email_rent_car" name="email" value="" />
    <input type="hidden" id="phone_rent_car" name="phone" value="" />

    <h1 class="blue">Car Rental</h1>
    <p>
        <input type="radio" id="rent_type" name="rent_type" value="Short Term" checked />Short Term&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="radio" id="rent_type" name="rent_type" value="Long Term" />Long Term
    </p>
        <p>Make</p>
        <p>
                        <select name="make" id="make">
                            <option value="">Please select</option>
<?php 
            foreach($make->result() as $row)
            { 
?>
                            <option value="<?php echo $row->id; ?>">
<?php 
                                echo $row->name;
?>
                            </option>
<?php
            }
?>        
                        </select>             
        </p>
        <p>Model</p>
        <p>
                        <select name="model" id="model">
                            <option value="">Please select</option>
                        </select>                         
        </p>
        <p>Year</p>
        <p>
    <select class="form" name="year">
        <option value="">Please select</option>
<?php 
            //date_default_timezone_set("GMT");
            $current_year = date("Y");

            for($counter = $current_year; $counter >= $current_year - 62; $counter--)
            { 
?>
            <option>
<?php 
                //echo $row->year 
                echo $counter;
?>
            </option>
<?php
            }
?>    
    </select>            
        </p>    
    <div id="container_short_term">
        <p>Request type</p>        
        <p>
            <select name="trip_type" class="selector">
                <option value="">Please select</option>
    <?php 
            foreach($trip_type->result() as $row)
            { 
    ?>
                <option>
    <?php 
                    echo $row->trip_type;
    ?>
                </option>
    <?php
            }
    ?>      
            </select>            
        </p>
        <!--
        <ul>
            <li>
                <input type="radio" name="trip_type" value="Airport Pick Up" checked />Airport Pick Up
            </li>
            <li>
                <input type="radio" name="trip_type" value="Airport Drop Off" />Airport Drop Off
            </li>
            <li>
                <input type="radio" name="trip_type" value="Hourly" />Hourly
            </li>
            <li>
                <input type="radio" name="trip_type" value="Half day" />Half day
            </li>
            <li>
                <input type="radio" name="trip_type" value="Full day" />Full day
            </li>
            <li>
                <input type="radio" name="trip_type" value="Custom Tour" />Custom Tour
            </li>
        </ul>
        <p style="padding: 0px;">&nbsp;</p>
        -->
        <p>Pickup Date &amp; Time</p>
        <p>
            <input type="text" name="from_date" id="from_date" value="" class="date" style="width: 150px;" />
            <input type="text" name="from_time" id="from_time" value="" class="time" style="width: 90px;" />
        </p>    
        <p>Return Date &amp; Time</p>
        <p>
            <input type="text" name="to_date" id="to_date" value="" class="date" style="width: 150px;" />
            <input type="text" name="to_time" id="to_time" value="" class="time" style="width: 90px;" />
        </p>    
        <p>Pickup address</p>
        <p>
            <input type="text" name="location_from" style="width: 92px;" />
            <select name="province_from" style="min-width: 152px;">
                <option value="">Please select</option>
    <?php 
            foreach($location->result() as $row)
            { 
    ?>
                <option>
    <?php 
                    echo $row->province;
    ?>
                </option>
    <?php
            }
    ?>      
            </select>
        </p>
        <p>Drop off address</p>
        <p>
            <input type="text" name="location_to" style="width: 92px;" />
            <select name="province_to" style="min-width: 152px;">
                <option value="">Please select</option>
    <?php 
            foreach($location->result() as $row)
            { 
    ?>
                <option>
    <?php 
                    echo $row->province;
    ?>
                </option>
    <?php
            }
    ?>      
            </select>
        </p>         
    </div> 
    <div id="container_long_term" class="hidden">    
        <p>Day</p>
        <p>
            <input type="text" name="number_day" id="number_day" value="" class="number" />
        </p>
        <p>Other requirements</p>
        <p>
            <textarea name="requirement" value="" style="height: 60px;">
            </textarea>
        </p>
    </div>
    <!--
    <div id="container_other_requirement">
    </div>
    -->
    <input type="hidden" value="Search" name="submit_rent_car" />
    <input type="button" value="Search" class="search" id="search_car" />
<?php  
    echo form_close();
?>
